<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>8.11. fpformat — Floating point conversions &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="8. String Services" href="strings.html" />
    <link rel="next" title="9. Data Types" href="datatypes.html" />
    <link rel="prev" title="8.10. stringprep — Internet String Preparation" href="stringprep.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="datatypes.html" title="9. Data Types"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="stringprep.html" title="8.10. stringprep — Internet String Preparation"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="strings.html" accesskey="U">8. String Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-fpformat">
<h1>8.11. <tt class="xref docutils literal"><span class="pre">fpformat</span></tt> &#8212; Floating point conversions<a class="headerlink" href="#module-fpformat" title="Permalink to this headline">¶</a></h1>
<p>
<span class="versionmodified">Deprecated since version 2.6: </span>The <tt class="xref docutils literal"><span class="pre">fpformat</span></tt> module has been removed in Python 3.0.</p>
<p>The <tt class="xref docutils literal"><span class="pre">fpformat</span></tt> module defines functions for dealing with floating point
numbers representations in 100% pure Python.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This module is unnecessary: everything here can be done using the <tt class="docutils literal"><span class="pre">%</span></tt> string
interpolation operator described in the <a class="reference external" href="stdtypes.html#string-formatting"><em>String Formatting Operations</em></a> section.</p>
</div>
<p>The <tt class="xref docutils literal"><span class="pre">fpformat</span></tt> module defines the following functions and an exception:</p>
<dl class="function">
<dt id="fpformat.fix">
<tt class="descclassname">fpformat.</tt><tt class="descname">fix</tt><big>(</big><em>x</em>, <em>digs</em><big>)</big><a class="headerlink" href="#fpformat.fix" title="Permalink to this definition">¶</a></dt>
<dd><p>Format <em>x</em> as <tt class="docutils literal"><span class="pre">[-]ddd.ddd</span></tt> with <em>digs</em> digits after the point and at least one
digit before. If <tt class="docutils literal"><span class="pre">digs</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>, the decimal point is suppressed.</p>
<p><em>x</em> can be either a number or a string that looks like one. <em>digs</em> is an
integer.</p>
<p>Return value is a string.</p>
</dd></dl>

<dl class="function">
<dt id="fpformat.sci">
<tt class="descclassname">fpformat.</tt><tt class="descname">sci</tt><big>(</big><em>x</em>, <em>digs</em><big>)</big><a class="headerlink" href="#fpformat.sci" title="Permalink to this definition">¶</a></dt>
<dd><p>Format <em>x</em> as <tt class="docutils literal"><span class="pre">[-]d.dddE[+-]ddd</span></tt> with <em>digs</em> digits after the  point and
exactly one digit before. If <tt class="docutils literal"><span class="pre">digs</span> <span class="pre">&lt;=</span> <span class="pre">0</span></tt>, one digit is kept and the point is
suppressed.</p>
<p><em>x</em> can be either a real number, or a string that looks like one. <em>digs</em> is an
integer.</p>
<p>Return value is a string.</p>
</dd></dl>

<dl class="exception">
<dt id="fpformat.NotANumber">
<em class="property">
exception </em><tt class="descclassname">fpformat.</tt><tt class="descname">NotANumber</tt><a class="headerlink" href="#fpformat.NotANumber" title="Permalink to this definition">¶</a></dt>
<dd>Exception raised when a string passed to <a title="fpformat.fix" class="reference internal" href="#fpformat.fix"><tt class="xref docutils literal"><span class="pre">fix()</span></tt></a> or <a title="fpformat.sci" class="reference internal" href="#fpformat.sci"><tt class="xref docutils literal"><span class="pre">sci()</span></tt></a> as the <em>x</em>
parameter does not look like a number. This is a subclass of <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a>
when the standard exceptions are strings.  The exception value is the improperly
formatted string that caused the exception to be raised.</dd></dl>

<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">fpformat</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">fpformat</span><span class="o">.</span><span class="n">fix</span><span class="p">(</span><span class="mf">1.23</span><span class="p">,</span> <span class="mf">1</span><span class="p">)</span>
<span class="go">&#39;1.2&#39;</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="stringprep.html"
                                  title="previous chapter">8.10. <tt class="docutils literal"><span class="pre">stringprep</span></tt> &#8212; Internet String Preparation</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="datatypes.html"
                                  title="next chapter">9. Data Types</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/fpformat.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="datatypes.html" title="9. Data Types"
             >next</a> |</li>
        <li class="right" >
          <a href="stringprep.html" title="8.10. stringprep — Internet String Preparation"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="strings.html" >8. String Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>